package com.lwj.service;

import com.github.dozermapper.core.Mapper;
import com.github.dozermapper.core.MapperModelContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@Component
public class DozerService {
    @Autowired
    Mapper mapper;

    public DozerService() {
    }

    public <T> List<T> mapList(List srcList, Class<T> clazz) {
        if (srcList != null && !srcList.isEmpty()) {
            List destList = new ArrayList(srcList.size());
            srcList.forEach((o) -> {
                destList.add(this.mapper.map(o, clazz));
            });
            return destList;
        } else {
            return Collections.emptyList();
        }
    }

    public <T> T map(Object source, Class<T> destinationClass) {
        return this.mapper.map(source, destinationClass);
    }

    public void map(Object source, Object destination) {
        this.mapper.map(source, destination);
    }

    public <T> T map(Object source, Class<T> destinationClass, String mapId) {
        return this.mapper.map(source, destinationClass, mapId);
    }

    public void map(Object source, Object destination, String mapId) {
        this.mapper.map(source, destination, mapId);
    }

    public MapperModelContext getMapperModelContext() {
        return this.mapper.getMapperModelContext();
    }
}
